package com.yc154.springmvc.po;

import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

@Data
public class User {

    Integer id;
    @NotNull(message = "用户名不能为null")  // name == null
    @NotBlank(message = "用户名不能为空字符串") // name.length == 0
    @Length(min = 2, max = 10, message = "账号必须是2~10个字符")
    String name;
    @NotEmpty(message = "密码不能为空")
    @Length(min = 6, max = 12, message = "密码必须是6~12个字符")
    String pwd;
    @NotEmpty(message = "你必须有爱好")
    @Size(min = 2, message = "你至少有2项目爱好")
    List<String> hobby;
    @Email(message = "邮箱格式错误")
    String email;
    @NotBlank(message = "性别不能为空")
    @Pattern(regexp = "男|女", message = "性别必须是男或女")
//    Character gender;
    String gender;
    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "1[3-9]\\d{9}", message = "手机号格式错误")
    String phone;

    /*
        解决日期转换问题方法:
        1. 使用json传送数据, springMVC会使用第三方工具实现json转对象
        2. 自定义转换器实现转换
     */

    // @NotNull(message = "生日不能为空")
    @Past(message = "生日必须是过去的时间")
    Date birthday;
//    java.sql.Date date;
//    LocalDate localDate;

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public List<String> getHobby() {
        return hobby;
    }

    public void setHobby(List<String> hobby) {
        this.hobby = hobby;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pwd='" + pwd + '\'' +
                ", hobby=" + hobby +
                ", email='" + email + '\'' +
                ", gender='" + gender + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}
